home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-05-01 | 2.6 KB | 135 lines | [TEXT/MPS ] |
- /************************************************************************
-
- Created: Monday, Sept 23, 1991
- TestSession.cp
- An inherited AFPSession class so that we can print buffers, errors etc. in MPW
- M.Vierling
-
-
- Copyright Apple Computer, Inc. 1991 - 1992
- All rights reserved
-
- ************************************************************************/
- #include <CType.h>
- #include <Stream.h>
- #include <stdlib.h>
- #include <Memory.h>
- #include <Resources.h>
- #include <Strings.h>
- #include <errors.h>
- #include "TestSession.h"
-
-
- void TestSession::SetPrint( Boolean printflag )
- {
- fPrintFlag = printflag;
- }
-
- void TestSession::SetPrintReply( Boolean printflag )
- {
- if (printflag)
- {
- this->SetPrint( true );
- }
- fPrintReply = printflag;
- }
-
- void TestSession::Debug( OSErr theErr, const char * message )
- {
- if (fPrintFlag)
- {
- if (theErr != 0)
- cout << message << theErr << "\n";
- else
- cout << message << "\n";
- }
- }
-
- void TestSession::PrintBuffer( Ptr Buffer, int BufferSize )
- {
- unsigned short * b;
- Ptr x;
-
- if (!fPrintFlag)
- return;
- cout << "hex dump: ";
-
- b = (unsigned short *)Buffer;
- for ( int i = 0; i < BufferSize; i += 2 )
- {
- cout.width(4);
- cout.fill('0');
- cout << hex << *b << " ";
- b++;
- };
-
- cout << dec << "\n";
-
- cout << "str dump: ";
- x = Buffer;
- for ( int j = 0; j < BufferSize; j++ )
- {
- if isgraph( *x )
- cout << *x;
- else
- cout << '.';
- x++;
- };
- cout << endl;
- }
-
- void TestSession::SetFileName( char * theName )
- {
- fSourceFileName = theName;
- }
-
- void TestSession::CheckErr( OSErr expectedError, int linenumber )
- {
- if (expectedError != fErrResult)
- {
- cerr << "File \"" << fSourceFileName << "\"; "
- << "line " << linenumber << " ### Error = " << fErrResult;
- if (expectedError != 0)
- cerr << " Expected error = " << expectedError << endl;
- else
- cerr << "\n";
- }
- }
-
- OSErr TestSession::DoAFPCommand( XPPParmBlkPtr theParamPtr )
- {
- Ptr Buffer;
- int BufferSize;
-
- Buffer = theParamPtr->XPP.cbPtr;
- BufferSize = theParamPtr->XPP.cbSize;
- this->PrintBuffer( Buffer, BufferSize );
-
- TAFPSession::DoAFPCommand( theParamPtr );
-
- if (fPrintReply)
- {
- Buffer = theParamPtr->XPP.rbPtr;
- BufferSize = theParamPtr->XPP.rbSize;
- this->PrintBuffer( Buffer, BufferSize );
- }
-
- return fErrResult;
- }
-
- OSErr TestSession::ISession( char * zoneName, char * serverName )
- {
- AddrBlock theAddress;
-
- theAddress = FindServer( zoneName, serverName );
- if ((theAddress.aNet == 0) && (theAddress.aNode == 0) && (theAddress.aSocket == 0))
- {
- cerr << "LLPT: NBP lookup failed for " << serverName << "\n";
- exit(1);
- }
- TAFPSession::ISession( theAddress );
- this->SetPathDelimiter( '@' );
- return fErrResult;
- }
-
-